package com.fanqiechaodan.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fanqiechaodan
 * @Classname Directory
 * @Description 组合节点
 */
public class Directory extends AbstractFile {

    private List<AbstractFile> fileList = new ArrayList<>();

    public Directory(String name) {
        super(name);
    }

    @Override
    public void add(AbstractFile file) {
        fileList.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        fileList.remove(file);
    }

    /**
     * 输入文件名;包含节点下的子节点
     */
    @Override
    public void display() {
        System.out.println("这是目录:" + name);
        fileList.forEach(AbstractFile::display);
    }
}
